<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/lib/html5shiv.js"></script>
<script type="text/javascript" src="/lib/respond.min.js"></script>
<![endif]-->
<link href="/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<link href="/static/layer/theme/default/layer.css"  rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>${siteName}后台登录</title>
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
  <div id="loginform" class="loginBox">
    <form class="form form-horizontal" id="loginForm" action="#" method="post">
      <div class="row cl">
        <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
        <div class="formControls col-xs-8">
          <input id="username" name="" type="text" placeholder="账户" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
        <div class="formControls col-xs-8">
          <input id="password" name="" type="password" placeholder="密码" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
        	<div id="vaptchaContainer" style="width: 300px;height: 36px;">
			    <div class="vaptcha-init-main">
			        <div class="vaptcha-init-loading">
			            <a href="/" target="_blank">
			                <img src="https://cdn.vaptcha.com/vaptcha-loading.gif" />
			            </a>
			            <span class="vaptcha-text">Vaptcha启动中...</span>
			        </div>
			    </div>
			</div>
		</div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
          <input name="" type="button" id="login" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
          <input name="" type="reset" id="reset" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
        </div>
      </div>
    </form>
  </div>
</div>
<div class="footer">Copyright ${siteName} by H-ui.admin v3.1</div>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="https://cdn.vaptcha.com/v2.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script th:inline="javascript">
vaptcha({
    //配置参数
    vid: "${vaptchaVID}", // 验证单元id
    type: 'click', // 展现类型 点击式
    container: '#vaptchaContainer' // 按钮容器，可为Element 或者 selector
}).then(function (vaptchaObj) {
	vaptchaObj.renderTokenInput('.login-form')//向表单中添加input标签
	vaptchaObj.render();//执行该方法, 生成验证码
	
	$("#login").on("click",function(){
		var vaptcha_token = vaptchaObj.getToken() ;
		var username = $("#username").val() ;
		var password = $("#password").val() ;
		console.info(vaptcha_token);
		if(vaptcha_token == '' || vaptcha_token == null){
			layer.msg('请进行人机验证');
			return ;
		}
		if(username == '' || username == null){
			layer.msg('请填写用户名');
			return ;
		}
		if(password == '' || password == null){
			layer.msg('请填写密码');
			return ;
		}
		$.ajax({
			url:"/enter",
			type:"post",
			dataType:"json",
			data:{"username":username,"password":password,"vaptcha_token":vaptcha_token},
			success:function(data){
				if(data.code == 200){
					//验证成功
					setCookie("token",data.data.token,data.data.tokentime) ;
					location.href = "/plat/index?loginId=" + data.data.loginId ; 
				}else{
					layer.msg(data.message) ;
					vaptchaObj.reset();
				}
			}
		})
	}) ;
	$("#reset").on("click",function(){
		vaptchaObj.reset();
	})
})

function setCookie(c_name,value,expiredays){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

</script>
</body>
</html>